package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dto.WarehouseDTO;
import com.itheima.pojo.Warehouse;
import com.itheima.service.WarehouseService;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/warehouse")
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;

    /**
     * 获取仓库分页列表
     *
     * @param page
     * @param dto
     * @return
     */
    @GetMapping("/page")
    public Page<WarehouseDTO> getWarehousePage(Page<WarehouseDTO> page, WarehouseDTO dto) {
        return warehouseService.getWarehousePage(page, dto);
    }

    /**
     * 获取仓库列表
     **/
    @GetMapping("/list")
    public Result list() {
        return Result.success(warehouseService.listAll());
    }

    /**
     * 获取仓库详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Warehouse getWarehouseById(@PathVariable Integer id) {
        return warehouseService.getWarehouseById(id);
    }

    /**
     * 保存仓库
     *
     * @param warehouse
     * @return
     */
    @PostMapping
    public Result saveWarehouse(@RequestBody Warehouse warehouse) {
        return Result.success(warehouseService.saveWarehouse(warehouse));
    }

    /**
     * 修改仓库
     *
     * @param warehouse
     * @return
     */
    @PutMapping
    public Result updateWarehouse(@RequestBody Warehouse warehouse) {
        return Result.success(warehouseService.updateWarehouse(warehouse));
    }

    /**
     * 删除仓库
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteWarehouse(@PathVariable Integer id) {
        return Result.success(warehouseService.deleteWarehouse(id)) ;
    }
}
